import request from "@/utils/request";
import {QueueRegCategoryModel} from "@/model/QueueRegCategoryModel";
import {QueueYjCategoryModel} from "@/model/QueueYjCategoryModel";
import {QueueRegItemModel} from "@/model/QueueRegItemModel";
import {QueueYjItemsModel} from "@/model/QueueYjItemsModel";
import {PagingModel} from "@/model/PagingModel";
import {QueueYjRoomItemsModel} from "@/model/QueueYjRoomItemsModel";

export default class YjRoomItemsApi {
    /**
     * 查询类目列表
     *
     */
    public static listYjRoomItems(pageIndex: number, pageSize: number, roomId: string = null, categoryId: string = null): Promise<PagingModel<QueueYjRoomItemsModel>> {
        return new Promise((resolve, reject) => {
            request({
                url: '/queue/yj/room_items/list',
                method: 'get',
                params: {
                   pageNum: pageIndex,
                   pageSize,
                   roomId,
                   categoryId
                }
            }).then((res: any) => {
                if (res.code === 200) {
                    const result = {
                        data: [],
                        pageSize: 0,
                        pageIndex: 1,
                        total: 0
                    }
                    result.data = res.rows.map(item => new QueueYjRoomItemsModel().deserialize(item))
                    result.pageIndex = pageIndex
                    result.pageSize = pageSize
                    result.total = +res.total
                    resolve(result)
                } else {
                    reject(res)
                }
            }, ()=> {reject()})
        })
    }

    public static updateYjRoomItemRelation(roomId: string, itemIds: string): Promise<Boolean> {
        return new Promise((resolve, reject) => {
            request({
                url: '/queue/yj/room_items/relation/update',
                method: 'POST',
                data: {
                    roomId,
                    itemIds
                }
            }).then((res: any) => {
                if (res.code === 200) {
                    resolve(true)
                } else {
                    reject(res)
                }
            }, ()=> {reject()})
        })
    }

}